import 'dart:math';
import 'package:flutter/material.dart';
import 'package:FlipClock/widgets/cell_card.dart';
import 'package:get/get.dart';

class FlipCard extends StatelessWidget {
  const FlipCard(
      this._timeNow, this._timeAgo, this._animation, this._side, this._index)
      : super();
  final RxString _timeNow;
  final RxString _timeAgo;
  final double _side;
  final RxInt _index;
  final Animation _animation;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: _side,
      height: _side,
      child: Stack(
        alignment: Alignment.center,
        children: [
          //behindTopCard
          Positioned(
            child: CellCard(_timeNow, _side, Alignment.topCenter),
            top: 0,
          ),

          //frontBottomCard
          Positioned(
            child: CellCard(_timeAgo, _side, Alignment.bottomCenter),
            bottom: 0,
          ),

          //flipCard
          Positioned(
            child: Transform(
              alignment: Alignment.bottomCenter,
              transform: Matrix4.identity()
                ..setEntry(3, 2, 0.001)
                ..rotateX(_animation.value),
              child: IndexedStack(
                index: _index.value,
                children: [
                  //behindBottomCard
                  Transform(
                    alignment: Alignment.center,
                    transform: Matrix4.rotationY(pi),
                    child: Transform.rotate(
                      angle: pi,
                      child: CellCard(_timeNow, _side, Alignment.bottomCenter),
                    ),
                  ),
                  //frontTopCard

                  CellCard(_timeAgo, _side, Alignment.topCenter),
                ],
              ),
            ),
            top: 0,
          ),
          Container(
            width: _side,
            height: 3,
            color: Theme.of(context).scaffoldBackgroundColor,
          ),
        ],
      ),
    );
  }
}
